import Vue from 'vue'
import Router from 'vue-router'
import Main from '../components/Main.vue'
import {
    MainChildren,
} from './Config';
import {accountAuthorization, hideNavBar, showTabBar} from "@/router/Middleware";

Vue.use(Router);

const router = new Router({
    // mode: 'history',
    base: process.env.BASE_URL,
    routes: [
        {
            path: '/',
            redirect: '/home',
            component: Main,
            children: MainChildren
        },
        {
            path: '*',
            redirect: '/home',
        }
    ]
});

router.beforeEach(async (to, from, next) => {
    // 设置需要显示 tabBar
    showTabBar(to, from, next);
    // 设置需要隐藏 navBar
    hideNavBar(to,  from, next);
    // 校验账号是否授权
    let accountAuth:boolean = await accountAuthorization(to,  from, next);
    if (!accountAuth) {
        next('/account-auth');
    }
    next();
});

export default router;
